/*
 * Copyright 2009 Johnson Consulting Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * 
 */
package com.johnsoncs.gwt.widgets.samples.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.johnsoncs.gwt.widgets.client.notifications.Notification;
import com.johnsoncs.gwt.widgets.client.notifications.Notifier;
import com.johnsoncs.gwt.widgets.client.util.TextUtils;

/**
 * @author wilj
 *
 */
public class NotificationsDemo extends Composite {
	private final HorizontalPanel panel = new HorizontalPanel();
	private int notificationSequence = 0;

	private final Notifier notifier = new Notifier(new Notifier.InitialPositionCallback() {
		@Override
		public int getBorderX() {
			return Math.max(0, Window.getClientWidth() - 10);
		}

		@Override
		public int getBorderY() {
			return Window.getScrollTop() + 10;
		}
	});

	private final TextArea notificationText = new TextArea();

	public NotificationsDemo() {
		super.initWidget(panel);
		notificationText.setText("This is a test notification. Hover to see the \"close\" icon.");
		notificationText.setSize("240px", "160px");
		panel.add(notificationText);
		panel.add(new Button("Add Notification", new ClickHandler() {
			@Override
			public void onClick(final ClickEvent event) {
				notificationSequence++;
				String message = notificationSequence + ": " + notificationText.getText();
				message = TextUtils.softWrap(message, 10);
				notifier.addNotification(new Notification(message, 10000));
			}
		}));
	}

}
